// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   HibernateTransactionInterceptor.java

package com.iphaeton.persistence.interceptor;

import com.iphaeton.exception.PersistenceException;
import com.iphaeton.persistence.hibernate.HibernatePService;
import java.lang.reflect.Method;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForward;
import org.springframework.aop.AfterReturningAdvice;

public class HibernateTransactionInterceptor
    implements AfterReturningAdvice
{

    public HibernatePService getPservice()
    {
        return pservice;
    }

    public void setPservice(HibernatePService pservice)
    {
        this.pservice = pservice;
    }

    public void afterReturning(Object returnValue, Method m, Object args[], Object target)
        throws Exception
    {
        ActionForward actionForward = (ActionForward)returnValue;
        if(actionForward == null)
        {
            pservice.rollback();
            pservice.release();
            logger.debug("After action invoking,the actionForward object is null,so roll back transaction!");
            return;
        }
        String retValue = actionForward.getName();
        if(retValue.equals("failure") || retValue.equals("error"))
        {
            pservice.rollback();
            pservice.release();
            logger.debug("After action invoking,the action result is error or failure,so roll back transaction!");
            return;
        }
        logger.debug("After action invoking,the return value is " + retValue);
        logger.debug("HibernatePService object is like " + pservice);
        try
        {
            pservice.commit();
        }
        catch(PersistenceException e)
        {
            pservice.rollback();
            logger.error("The transaction has been rolled back!", e);
            e.printStackTrace();
        }
        pservice.release();
    }

    public HibernateTransactionInterceptor()
    {
        pservice = null;
    }

    private static Logger logger;
    private HibernatePService pservice;
    static Class class$0; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.persistence.interceptor.HibernateTransactionInterceptor.class.getName());
    }
}
